﻿<div id="information">
<?php
include "../templates/db/db.php";
?>
<br />
<?php
$id = (int)$_GET['id'];
/* защита по ид */
	if(!isset($id) || !is_numeric($id) || $id<1){
	echo "<h2>Не мога да намеря страницата..</h2>";
	}else {
	?>
	<br /><br />
	<?php 
	$sell = "SELECT * FROM cat_t WHERE id='".$_GET['id']."'";
	$sell_q = mysql_query($sell);
	$row_ll = mysql_fetch_assoc($sell_q);
	?>
	<a href="<?php echo 'post_comment.php?id='.$_GET['id'].'';?>" style='color: #000; text-decoration: none;'>Добави коментар</a><br /><br />
	<div id='boxx_coms'>
	<?php
	   if($_GET['moda']=="delete"){
	         $delete_f='DELETE FROM com_t WHERE id="'.$_GET['mnenie'].'"';
			 $results_delete_f=mysql_query($delete_f);
			
			echo '
			<script type="text/javascript">
			alert("Успешно Изтриване!");
			</script>
			';
			echo '<meta http-equiv="refresh" content="0;url=see_t.php?id='.$_GET['id'].'">';
	   } else {
		$selll_c = mysql_query('SELECT * FROM com_t WHERE title_t='.$_GET['id'].'');

		if(mysql_num_rows($selll_c) == 0){
		echo '<p class="error">Няма мнения към тази тема!</p>';
		} else {
		while($row_cc = mysql_fetch_assoc($selll_c)) {
		
		 $select_a='SELECT * FROM avatars WHERE from_who="'.$row_cc['who_added'].'" LIMIT 1';
		 $res_a=mysql_query($select_a);
		 $row_a=mysql_fetch_assoc($res_a);
		 
		 if(mysql_num_rows($res_a)==1){
	      $img="<img src='../user_pics/".$row_a[pic_name]."' width='110' height='110' style='margin-left: 10px; box-shadow: 5px 5px 5px #000' alt='avatar'/>";
	   }
	   else{
	      $img="<img src='../user_pics/default.png' width='110' height='110' style='margin-left: 10px; box-shadow: 5px 5px 5px #000' alt='avatar'/>";
	   }
		?>
		<div id='comments'>
		<table width='100%' style='background: #C4C4C4; border: 1px solid gray'> 
		<tr>
			<td style='background: none; color: #000;'>
				Тема: <b><?php echo $row_ll['t_title']; ?></b>
			</td>
		</tr>
		<tr>
		<td style='background: none; color: #000;'>
				Мнение от <b><?php echo $row_cc['who_added']; ?></b>
				- <?php echo date('Y-m-d / G:i:s', $row_cc['date'])?>
			</td>
		</tr>
		<?php
		if($_SESSION['username']=="admin"){
	      echo '<a href="see_t.php?id='.$_GET['id'].'&amp;mnenie='.$row_cc['id'].'&amp;moda=delete" class="show">
	      <img src="../img/delete.png" width="15px" height="15px" alt="delete" style="position: relative; left: 600px; bottom: -25px;"/></a>';
	    }
		?>
		</table>
		<div id='real_com'>
		<table style="margin-top: 10px;">
		<tr>
		<td width="510px;"><div style="border: 1px solid gray; min-height: 100px; padding-top: 10px; padding-left: 10px; text-indent: 30px;"><?php echo ucfirst($row_cc['comment']);?></div></td>
		<td style="float: right;"><?php echo $img; ?></td>
		</tr>
		</table>
		</div>
		<br />
		</div>
		<?php
		}
		}
		?>
		</div>
		<br /><br />
			<?php
	}
	}
	?>
<br />
</div>